package com.example.lenovo.a203_yhy_ordering_3.fragments;

import android.app.Fragment;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by lenovo on 2018/11/19.
 */

public class BaseFragment extends android.support.v4.app.Fragment{

    private final String KEY_SESSION_ID = "sessionId";//与sharedpreferences保存的关键字一致
    private final String KEY_USERNAME = "userName";//与sharedpreferences保存的关键字一致
    private final String FILE = "loginPref";//与sharedpreferences的文件名一致
    private final int MODE = Context.MODE_PRIVATE;
    private SharedPreferences sharedPreferences;
    protected Context context;

    @Override  //Fragment生命周期方法
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
        sharedPreferences = context.getSharedPreferences(FILE, MODE);
    }
    //返回sessionid
    protected String getSessionId(){
        return sharedPreferences.getString(KEY_SESSION_ID, "");
    }
    //返回username
    protected String getUserName(){
        return sharedPreferences.getString(KEY_USERNAME, "");
    }

}
